﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using VacationDaysCommons;
using VacationDaysClient.CustomControls;

namespace VacationDaysClient
{
    /// <summary>
    /// Interaction logic for PMWindow.xaml
    /// </summary>
    public partial class UserWindow : Window
    {
        private VDEmployee currentUser;
        public UserWindow(VDEmployee userInfo)
        {
            currentUser = userInfo;
            InitializeComponent();
            userFullNameBox.Content = string.Format("{0}, {1}", userInfo.LastName, userInfo.FirstName);
            
            PMEmployeesItem.Visibility = System.Windows.Visibility.Collapsed;
            HREmployees.Visibility = System.Windows.Visibility.Collapsed;
            
            if (userInfo.Role == EmployeeRole.PM)
            {
                PMEmployeesItem.Visibility = System.Windows.Visibility.Visible;
            }
            if (userInfo.Role == EmployeeRole.HRPeople)
            {
                HREmployees.Visibility = System.Windows.Visibility.Visible;
            }

            
        }

        private void NewRequest(object z, object zz)
        {
            //Show new req window
            Application.Current.MainWindow = new RequestEditor(currentUser);
            var result = Application.Current.MainWindow.ShowDialog();

            if (result.GetValueOrDefault() == true)
            {
                // refresh something
                MessageBox.Show("Added new request");
                if (z != null && (z as UserVacationDaysList != null))
                {
                    (z as UserVacationDaysList).RefreshContent();
                }
            }
            return;
        }

        private void MyRequestsList_Click(object sender, RoutedEventArgs e)
        {
            var vacationDayLister = new UserVacationDaysList(currentUser.Id);
            contentControl1.Content = vacationDayLister;
            vacationDayLister.NewRequestClicked += NewRequest;
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            inboxTreeItem.IsSelected = true;
            //myRequestsTreeItem.IsSelected = true;
           // InboxItem_Selected(null, null);
        }

        private void PMEmployeesRequests_Selected(object sender, RoutedEventArgs e)
        {
            var vacationDayLister = new PMUserVacationRequests(currentUser.Id);
            contentControl1.Content = vacationDayLister;
            //vacationDayLister.NewRequestClicked += NewRequest;
        }

        private void InboxItem_Selected(object sender, RoutedEventArgs e)
        {
            var inboxLister = new UserInboxControl(currentUser.Id);
            contentControl1.Content = inboxLister;
        }


    }
}
